<template>
	<view class="">
		<block>
			<view class="SearchItem">
				<input type="text" v-model="searchValue" @confirm='ToSearchPage()' placeholder="搜索商品" />
			</view>

			<view class="page-section-spacing">
				<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
					:duration="duration">
					<swiper-item v-for="(i,n) in BannerList" :key='n'>
						<image style="width: 100%;height: 100%;" :src="i.image" mode=""></image>
					</swiper-item>

				</swiper>
			</view>
			<view class="CardContainer">
				<view class="ccmain" v-for="(i,n) in CardContainerList" :key='n' @tap="jump(i.path)">
					<view class="ccimg">
						<image :src="i.img" mode=""></image>
					</view>
					<text>{{i.text}}</text>
				</view>
			</view>
			<view class="ModuleContainer">
				<view class="item" v-for="(i,n) in cardList" :key='n' @tap="jump(i.path)">
					<view class="moduleheader">
						<view class="moduleinfo">
							<text class="t1">{{i.title}}</text>
							<text class="t2"></text>
							<text class="kejian">
								{{i.text}}
							</text>
						</view>
						<view class="moduleimg">
							<image :src="i.img" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="CardContainer2">
				<view class="ccmain" v-for="(i,n) in CardContainerList2" :key='n' @tap="jump(i.path)">
					<text>{{i.text}}</text>
					<view class="ccimg">
						<image :src="i.img" mode=""></image>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import wanlShopPage from '@/components/wanl-shop/page';
	import wanlShopFind from '@/components/wanl-shop/find';
	import wanlShopCategory from '@/components/wanl-shop/category';

	export default {
		components: {
			wanlShopPage,
			wanlShopFind,
			wanlShopCategory
		},
		computed: {
			...mapState(['common', 'user', 'update'])
		},

		data() {
			return {
				CardContainerList: [
					// {
					// 	text: '考试复习',
					// 	img: require('@/static/images/index/6192.png'),
					// 	path: '/pages/teacher/practiceList'
					// },
					// {
					// 	text: '线上考试',
					// 	img: require('@/static/images/index/6193.png'),
					// 	path: '/pages/teacher/ExamList'
					// },
					{
						text: '师资培训',
						img: require('@/static/images/index/6194.png'),
						path: '/pages/teacher/teacherTrain?type=3'
					},
					{
						text: '学生培训',
						img: require('@/static/images/index/6195.png'),
						path: '/pages/teacher/teacherTrain?type=2'
					},
					{
						text: '茶会培训',
						img: require('@/static/images/index/6196.png'),
						path: '/pages/teacher/teacherTrain?type=1'
					},
					{
						text: '茶产品',
						img: require('@/static/images/index/6199.jpg'),
						path: '/pages/product/list'
					},
					// {
					// 	text: '证书查询',
					// 	img: require('@/static/images/index/6197.png'),
					// 	path: '/pages/teacher/certificate'
					// },
					{
						text: '专家名师',
						img: require('@/static/images/index/6198.png'),
						path: '/pages/teacher/teacherlist'
					},
				],
				cardList: [{
						title: '教师专用',
						text: '课程套餐',
						img: require('@/static/images/index/6181.png'),
						path: "/pages/teacher/classPackage",

					},
					{
						title: '创意无限',
						text: '拓展练习',
						img: require('@/static/images/index/6182.png'),
						path: "/pages/teacher/ExpanTest",

					},
					{
						title: '老师必学',
						text: '教学过程',
						img: require('@/static/images/index/6183.png'),
						path: "/pages/teacher/TeachLesson",

					}, {
						title: '愉悦生活',
						text: '精品微课',
						img: require('@/static/images/index/6184.png'),
						path: "/pages/teacher/NiceLesson",

					}, {
						title: '在线精品',
						text: '电子刊物',
						img: require('@/static/images/index/6191.png'),
						path: '/pages/teacher/eBooks'
					}, {
						title: '妙趣横生',
						text: '免费学习',
						img: require('@/static/images/index/6186.png'),
						path: "/pages/teacher/FreeStudy",

					},
					{
						title: '精彩纷呈',
						text: '茶会定制',
						img: require('@/static/images/index/6189.png'),
						path: "/pages/teacher/TeaCustom",
					},

					{
						title: '共创共赢',
						text: '合作资源',
						img: require('@/static/images/index/6190.png'),
						path: "/pages/teacher/cooperations",
					},
				],
				headHeight: 75,
				windowHeight: 0,
				headTop: 0,
				currentItemId: 'home',
				currentData: {},
				scrollLeft: 0,
				isModal: false,
				indicatorDots: true,
				BannerList: [],
				autoplay: true,
				interval: 2000,
				duration: 500,
				searchValue:"",
				contentText: {
					contentdown: '下拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '我是有底线的'
				},
				CardContainerList2: [
					{
						text: '考试复习',
						img: require('@/static/images/index/6192.png'),
						path: '/pages/teacher/practiceList'
					},
					{
						text: '线上考试',
						img: require('@/static/images/index/6193.png'),
						path: '/pages/teacher/ExamList'
					},
					{
						text: '证书查询',
						img: require('@/static/images/index/6197.png'),
						path: '/pages/teacher/certificate'
					},
				],
			};
		},
		onShow() {
			// #ifdef APP-PLUS
			// plus.navigator.setFullscreen(false);
			// #endif
			// 计算页面尺寸
			let sys = this.$wanlshop.wanlsys();
			this.headTop = sys.top;
			this.headHeight = sys.height + uni.upx2px(60);
			// this.windowHeight = sys.windowHeight;
			setTimeout(() => {
				// uni.setNavigationBarColor({
				// 	frontColor: this.$store.state.common.modulesData.homeModules.page ?
				// 		this.$store.state.common.modulesData.homeModules.page.style
				// 		.navigationBarTextStyle : '',
				// 	backgroundColor: this.$store.state.common.modulesData.homeModules.page ?
				// 		this.$store.state.common.modulesData.homeModules.page.style
				// 		.navigationBarBackgroundColor : ''
				// });
			}, 200);
			this.getListData()
		},
		onReady() {
			// 判断网络类型
			uni.getNetworkType({
				success: res => {
					if (res.networkType == '2g' || res.networkType == '3g' || res.networkType == '4g') {
						this.$wanlshop.msg('当前使用非WIFI环境，请注意流量使用');
					} else if (res.networkType == 'none') {
						this.$wanlshop.msg('没有网络');
					}
				}
			});
		},
		methods: {
			...mapActions({
				download: 'update/download', // 立即下载
				ignore: 'update/ignore' // 忽略更新
			}),
			getListData() {
				this.$api.get({
					url: '/index/index',

					success: res => {
						console.log(res)
						this.BannerList = res.banner
						let shareModal = {
							title:res.share_title,
							Image:res.share_image,
							link:res.share_url,
							desc:res.share_text
						}
						uni.setStorageSync('shareModal',shareModal)
						
					}
				})
			},

			jump(path) {
				console.log(path)
				uni.navigateTo({
					url: path
				})
			},
			// 选择Tag
			handleSelect(id, index) {
				this.currentItemId = id;
				this.scrollLeft = (index - 1) * 50;
			},
			// 弹出层
			handleModal() {
				this.isModal = !this.isModal;
			},
			// 动画
			animationFinish(e) {
				//#ifdef APP-PLUS
				this.changeCurrent(e);
				//#endif
			},
			// 滚动的tag
			changeCurrent(e) {
				this.currentItemId = e.detail.currentItemId;
				this.scrollLeft = (e.detail.current - 1) * 50;
			},
			// 一下扫码
			scanCode() {
				// #ifndef H5
				uni.scanCode({
					success: res => {
						var QRcode = this.getUrlParam(res.result);
						switch (QRcode.QRtype) {
							case 'goods':
								this.onGoods(QRcode.id);
								break;
							case 'user':
								this.$wanlshop.to(`/pages/user/info?id=${QRcode.id}`);
								break;
							case 'category':
								this.$wanlshop.on('/pages/category');
								break;
							case 'page':
								this.$wanlshop.to(`/pages/page/index?id=${QRcode.id}`);
								break;
							case 'shop':
								this.onShop(QRcode.id);
								break;
							case 'live':
								// #ifdef APP-PLUS || MP-WEIXIN
								this.$wanlshop.auth(`/pages/shop/live/live`);
								// #endif
								// #ifndef APP-PLUS || MP-WEIXIN
								this.$wanlshop.msg('目前只开放App和微信小程序直播');
								// #endif
								break;
							case 'chat':
								this.toChat(QRcode.id);
								break;
						}
					}
				});
				// #endif
				// #ifdef H5
				this.$wanlshop.msg('暂不支持H5扫码');
				// #endif
			},
			// 解析Url
			getUrlParam(url) {
				var obj = {};
				var data = url.split('?')[1].split('&');
				for (var i = 0; i < data.length; i++) {
					var res = data[i].split('=');
					obj[res[0]] = res[1];
				}
				return obj;
			},
			// 搜索
			handleSearch(text) {
				this.$wanlshop.to(`/pages/page/search?type=goods&keywords=${text}`, 'fade-in', 100);
			},
				
			ToSearchPage(){
				if(this.searchValue){
					uni.navigateTo({
					url:`/pages/teacher/SearchPage?keywords=${this.searchValue}`
					})
				}
			}

		}
	};
</script>

<style lang="scss">
	// 	&__head {
	// 		position: fixed;
	// 		top: 0;
	// 		left: 0;
	// 		right: 0;
	// 		z-index: 999;
	// 		background-size: 100% auto;
	// 		background-repeat: no-repeat;

	// 		.navigater {
	// 			height: 86rpx;
	// 			padding-left: 25rpx;
	// 			padding-right: 25rpx;
	// 			/* #ifdef MP */
	// 			padding-right: 220rpx;

	// 			/* #endif */
	// 			.search {
	// 				flex: 1;
	// 				background-color: #fff;
	// 				height: 66rpx;
	// 				border: 2rpx solid #fff;

	// 				.icon {
	// 					margin: 0 20rpx;
	// 				}

	// 				swiper {
	// 					height: 100%;
	// 					width: 100%;
	// 					margin-right: 10rpx;

	// 					swiper-item {
	// 						display: flex;
	// 						align-items: center;
	// 					}
	// 				}
	// 			}
	// 		}

	// 		.toolbar {
	// 			.scroll {
	// 				flex: 1;
	// 				white-space: nowrap;
	// 				overflow: hidden;
	// 				width: 100%;

	// 				&__item {
	// 					position: relative;
	// 					z-index: 2;
	// 					font-size: 28rpx;
	// 					display: inline-flex;
	// 					height: 58rpx;
	// 					align-items: center;
	// 					margin-right: 40rpx;

	// 					&.action {
	// 						position: relative;
	// 						font-weight: bold;
	// 						font-size: 30rpx;

	// 						&::after {
	// 							content: ' ';
	// 							position: absolute;
	// 							bottom: 0;
	// 							left: 50%;
	// 							transform: translateX(-50%);
	// 							height: 4rpx;
	// 							width: 30rpx;
	// 							border-radius: 6rpx;
	// 							background-color: #fff;
	// 						}
	// 					}
	// 				}
	// 			}

	// 			.category {
	// 				box-shadow: #eee -16rpx 0 16rpx -16rpx;
	// 				height: 58rpx;
	// 				font-size: 28rpx;
	// 				padding-left: 25rpx;
	// 			}
	// 		}
	// 	}

	// &__main {
	// 	position: relative;
	// 	z-index: 99;
	// }

	.WANL-MODAL {
		.cu-modal {
			&.top-modal {
				background: rgba(0, 0, 0, 0.6);
				text-align: inherit;

				.cu-dialog {
					background: #fff;
					border-radius: 0 0 18rpx 18rpx;

					.category {
						display: grid;
						grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
						grid-auto-flow: row dense;
						grid-gap: 16rpx;

						.item {
							display: flex;
							align-items: center;
							justify-content: center;
							padding: 12rpx 0;
							border: 2rpx solid transparent;

							&.action {
								background-color: transparent;
								border-color: #f40;
								color: #f40;
								font-weight: bold;
							}
						}
					}
				}
			}
		}
	}

	.CardContainer {
		// height: 370rpx;
		background: #fff;
		padding: 30rpx ;
		// text-align: center;
		font-size: 20rpx;
		color: #333;
		display: flex;
		flex-wrap: wrap;

		.ccmain {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			// text-align: center;
			.ccimg {
				width: 92rpx;
				height: 92rpx;
				margin-bottom: 8rpx;

				// background-color: pink;
				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		view {
			width: 20%;
		}
	}
	.CardContainer2{
		background: #fff;
		padding: 20rpx ;
		font-size: 20rpx;
		color: #333;
		display: flex;
		flex-wrap: wrap;
		margin: 0 30rpx 30rpx;
		.ccmain {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 33.33%;
		
			// text-align: center;
			.ccimg {
				width: 92rpx;
				height: 92rpx;
				margin-left: 10rpx;
		
				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.ModuleContainer {
		display: flex;
		flex-wrap: wrap;
		margin: 0 30rpx 30rpx;
		justify-content: space-between;


		.moduleheader {
			display: flex;
			justify-content: space-around;
			align-items: center;

			.moduleinfo {
				.t1 {
					display: block;
					width: 104rpx;
					height: 28rpx;
					font-size: 20rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #C3A16E;
					padding: 0;
				}

				.t2 {
					width: 104rpx;
					height: 4rpx;
					display: block;
					background-color: #D5EFEF;
					margin: 12rpx 0;
				}

				.kejian {
					font-size: 26rpx;
					width: 104rpx;
					display: block;
					font-weight: bold;
					font-family: PingFang SC-Bold, PingFang SC;
					color: #333333;
				}
			}

			.moduleimg {
				width: 178rpx;
				height: 188rpx;

				// background-color: pink;
				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.item {
			width: 336rpx;
			height: 220rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			margin-top: 20rpx;
			box-sizing: border-box;
			padding: 16rpx 16rpx 16rpx 20rpx;
		}
	}


	.SearchItem {
		input {
			width: 345px;
			height: 30px;
			background: #FFFFFF;
			border-radius: 25px 25px 25px 25px;
			opacity: 1;
			border: 1px solid #DDDDDD;
			padding-left: 20rpx;
		}


		padding: 20px;
		background: #d0dee1;
	}
</style>
